package com.apex.controller;


import com.apex.dto.ClientDTO;
import com.apex.pojo.Client;
import com.apex.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author George
 * @since 2023-06-13
 */
@RestController
public class ClientController {

    @Autowired
    private ClientService clientService;

    @GetMapping(value = "/management")
    public ModelAndView clientQuery(Model model, ModelAndView modelAndView){

        List<Client> client = clientService.ClientQuery();
        model.addAttribute("clients",client);


        modelAndView.setViewName("BackEnd/customer-management");
        return modelAndView;
    }

    @RequestMapping(value = "/information/{id}")
    public ModelAndView clientInformation(Model model, ModelAndView modelAndView, @PathVariable String id){

        List<ClientDTO> clientByIdWithDetail = clientService.getClientByIdWithDetail(id);
        model.addAttribute("clientByIdWithDetails",clientByIdWithDetail);
        modelAndView.setViewName("BackEnd/customer-information");
        return modelAndView;
    }
}

